package com.cicc.beergamevirtualsimulationsystem.controller;

import com.cicc.beergamevirtualsimulationsystem.entity.DictEntity;
import com.cicc.beergamevirtualsimulationsystem.entity.RoleTypeEntity;
import com.cicc.beergamevirtualsimulationsystem.model.R;
import com.cicc.beergamevirtualsimulationsystem.model.parameter.req.ParameterCreatorReq;
import com.cicc.beergamevirtualsimulationsystem.service.DictService;
import com.cicc.beergamevirtualsimulationsystem.service.ParameterService;
import com.cicc.beergamevirtualsimulationsystem.service.RoleTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 公用模块
 */
@RestController
@RequestMapping("/api/common")
@RequiredArgsConstructor
public class CommonController {

    private final DictService dictService;

    private final RoleTypeService roleTypeService;

    private final ParameterService parameterService;

    /**
     * 添加字典数据
     */
    @PostMapping("/dict")
    public R addDict(@RequestBody DictEntity dictEntity){
        dictService.addDict(dictEntity);
        return R.ok();
    }

    /**
     * 查询页面字典数据
     * @param pageName
     * @return
     */
    @GetMapping("/dict/{pageName}")
    public R<Map<String, List<DictEntity>>> queryDict(@PathVariable String pageName){
        return R.ok(dictService.queryDict(pageName));
    }


    /**
     * 添加游戏角色
     */
    @PostMapping("/role")
    public R addRole(@RequestBody RoleTypeEntity roleTypeEntity){
        roleTypeService.save(roleTypeEntity);
        return R.ok();
    }
    /**
     * 创建游戏参数
     * @param parameterCreatorReq
     * @return
     */
    @PostMapping("/parameter")
    public R createreParameter(@RequestBody ParameterCreatorReq parameterCreatorReq){
        return R.ok(parameterService.createParameter(parameterCreatorReq));
    }

}
